<?php
/**
	 * @file
	 * @author Anthony Free
	 * @package fwork
	 * @subpackage sql
	 * @version 20110930
	 */
	 /**
	  *
	  */

	/**
	 *
	 */

    // Socket or Host:Port?
    if($_FWORK['MYSQL_CONF']['SOCK_MODE'] === true) {
	$host_dest = $_FWORK['MYSQL_CONF']['SOCKET'];
    } else {
	$host_dest = $_FWORK['MYSQL_CONF']['HOST'];
	if($_FWORK['MYSQL_CONF']['PORT'] !== null) {
	    $host_dest .= $_FWORK['MYSQL_CONF']['PORT'];
	}
    }
    
    /**
     * Error Reporting System for this module, will select generic php output or libdebug based on settings in incl_fwork.php
     * @global type $_FWORK
     * @param type $link
     * @param type $param
     * @throws Exception 
     */
    function E_SQL(&$link, &$param) {
	global $_FWORK;
	if(!$param) {
	    if($_FWORK['MODULES']['LIBDEBUG'] === true) {
		throw new Exception("<b><i>Fwork</b> MySQLi error Handler</i>:<br />".  mysqli_error($link));
	    } else {
		trigger_error(mysqli_error($link), E_FATAL);
		die();
	    }
	}
    }
    $sql_conx = new mysqli();
    $sql_conx->connect($host_dest, $_FWORK['MYSQL_CONF']['USER'], $_FWORK['MYSQL_CONF']['PASS']);
    E_SQL($sql_conx->connect_errno, $sql_conx);
    
    // Select the correct database
    $dbsel_conx = $sql_conx->select_db($_FWORK['MYSQL_CONF']['DBASE']);
    E_SQL($sql_conx, $dbsel_conx);
?>
